let n = 19
var isHappy = function(n) {
    let map = new Map()
    while(!(map.has(n))){
        map.set(n,1)
        n = pfs(n)
    if(n===1){
        return true
    }
      }
return false
};

function pfs(n){
    let result =0
    while(n!==0){
        result = result + (n%10)*(n%10)
        n = Math.floor(n/10)
    }
    return result;
}
console.log(isHappy(n));
